package edu.fanhuiling.blogsystem.config;

import edu.fanhuiling.blogsystem.common.Constants;
import edu.fanhuiling.blogsystem.model.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ResponseBody  //返回的是数据   比添加该注解会报错401 401=4
@ControllerAdvice
public class ErrorAdvice{
    @ExceptionHandler
    public Result errorHandler(Exception e){
        Result result=new Result<>();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrMsg("内部发生错误，请联系管理员 ");
        result.setData(null);
        return result;
    }
}
